package com.ryan.route.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ryan.route.entity.RouteComment;
import com.ryan.route.mapper.RouteCommentMapper;
import com.ryan.route.service.RouteCommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 评论 服务实现类
 * </p>
 *
 * @author ryan
 * @since 2020-08-03
 */
@Service
public class RouteCommentServiceImpl extends ServiceImpl<RouteCommentMapper, RouteComment> implements RouteCommentService {

    /**
     * 根据路线id获取路线评论
     * @param pageIndex
     * @param pageSize
     * @param routeId
     * @return
     */
    @Override
    public Map<String, Object> GetCommentList(long pageIndex, long pageSize, String routeId) {
        QueryWrapper<RouteComment> wrapper = new QueryWrapper<>();
        wrapper.eq("route_id",routeId);
        Page<RouteComment> page = new Page<>(pageIndex,pageSize);
        baseMapper.selectPage(page,wrapper);
        Map<String, Object> map = new HashMap<>();
        map.put("list", page.getRecords());
        map.put("current",page.getCurrent());
        map.put("pages",page.getPages());
        map.put("size",page.getSize());
        map.put("total",page.getTotal());
        map.put("hasNext",page.hasNext());
        map.put("hasPrevious",page.hasPrevious());
        return map;
    }
}
